﻿Public Class ZeroWidthPanel
    Inherits Panel

    Protected Overrides Function MeasureOverride(s As Size) As Size
        Dim measureSize As New Size(Double.PositiveInfinity, s.Height)
        For Each u In Children.Cast(Of UIElement)()
            u.Measure(measureSize)
        Next
        Return If(Double.IsInfinity(s.Height), _
                  New Size(0, Children.Cast(Of UIElement).Max(Function(u) u.DesiredSize.Height)), _
                  New Size(0, s.Height))
    End Function

    Protected Overrides Function ArrangeOverride(s As Size) As Size
        For Each u In Children.Cast(Of UIElement)()
            u.Arrange(New Rect(-u.DesiredSize.Width / 2, 0, u.DesiredSize.Width, s.Height))
        Next
        Return s
    End Function

End Class
